/* Account.cpp
Michael Zahniser

Function definitions for the Account class.
*/

#include "Account.h"



Account::Account()
  : balance(0.0), isChecks(false)
{
}



Account &Account::operator+=(double amount)
{
    Add(amount);
	return *this;
}



Account &Account::operator-=(double amount)
{
    Add(-amount);
	return *this;
}



double Account::Balance() const
{
    return type.IsInverted() ? -balance : balance;
}



void Account::Add(double amount)
{
    balance += amount;
}



// Set the balance of this account to zero.
void Account::Clear()
{
    balance = 0.0;
}



void Account::SetType(AccountType accountType)
{
    type = accountType;
}



AccountType Account::Type() const
{
    return type;
}



void Account::SetFlag(const string &flag, bool isSet)
{
    if(flag == "Checks")
	isChecks = isSet;
}



bool Account::IsChecks() const
{
    return isChecks;
}



// Print this account's info.
void Account::PrintInfo(ostream &out) const
{
    out<<"(type: "<<type.Name()<<")";
    if(isChecks)
    {
	out<<" [flags:";
	if(isChecks)
	    out<<" Checks";
	out<<"]";
    }
}
